package com.qm.console.controller.rest;

import com.alibaba.fastjson.JSONObject;
import com.qm.console.controller.response.BaseResponse;
import com.qm.console.model.ModuleClassConfig;
import com.qm.console.model.SysOperationLog;
import com.qm.console.service.SysOperationLogService;
import com.qm.console.controller.response.BaseResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Created by Edison.hu on 18/9/11.
 */

@RestController
@RequestMapping("/sysLog")
public class SysOperationLogController {

    @Autowired
    SysOperationLogService sysOperationLogService;

    @RequestMapping(value = "/logList",method  = RequestMethod.GET)
    @RequiresPermissions("sysLog:view")
    public JSONObject systemLogList(@RequestParam(value="username", required=false) String username,
            @RequestParam(value="moduleId", required=false) Integer moduleId,
            @RequestParam(value="offset", required=false, defaultValue="0") int offset,
            @RequestParam(value="limit", required=false, defaultValue="20") int limit,
            @RequestParam(value="startTime", required=false) String startTime,
            @RequestParam(value="endTime", required=false) String endTime,
            @RequestParam(value="orderType", required=false, defaultValue="DESC") String orderType,
            @RequestParam(value="orderBy", required=false, defaultValue="visit_time") String orderBy){

        int count=sysOperationLogService.getSysLogCount(username,moduleId,startTime,endTime);
        java.util.List<SysOperationLog> list = sysOperationLogService.getSysLogList(username,moduleId,startTime,endTime,offset,limit,orderBy,orderType);
        BaseResponse results = new BaseResponse<>(list,count);
        return results;
    }

    @RequestMapping(value = "/moduleOptions",method  = RequestMethod.GET)
    @RequiresPermissions("sysLog:view")
    public JSONObject getModuleList(){

        List<ModuleClassConfig> list=sysOperationLogService.getAllModuleClass();
        BaseResponse results = new BaseResponse(list);
        return results;
    }

}
